#include "TemplateElement.h"
#include <iostream>

int main()
{
    vector<double> p0 = {-1, -1};
    vector<double> p1 = {0, 1};
    vector<double> p2 = {1, 1};
    vector<double> p3 = {-1, 1};
    Point<2> P0(p0);
    Point<2> P1(p1);
    Point<2> P2(p2);
    Point<2> P3(p3);
    vector<Point<2>> d = {P0, P1, P2, P3};
    Domain<2> *D = new Rectangle2D(d);
    vector<int> seg1 = {4, 4};
    // 1阶测试
    Mesh<2> *M1 = new Q1Mesh(D, seg1);
    Grid<2> g1 = M1->getGrid(3);
    TemplateElement<2> *E1 = new Quadrilateral_1_Element();
    E1->reinit(g1, *M1);
    for (int i = 0; i < 4; i++)
        cout << E1->getGlobalIndex(i) << endl;
    // for (int i = 0; i < E1->getBoundaryDofsonGrid().size(); i++)
    //     cout << E1->getBoundaryDofsonGrid()[i] << endl;
    cout << "-------------------------" << endl;
    // 2阶测试
    Mesh<2> *M2 = new Q2Mesh(D, seg1);
    Grid<2> g2 = M2->getGrid(4);
    TemplateElement<2> *E2 = new Quadrilateral_2_Element();
    E2->reinit(g2, *M2);
    for (int i = 0; i < 9; i++)
        cout << E2->getGlobalIndex(i) << endl;
    // for (int i = 0; i < E2->getBoundaryDofsonGrid().size(); i++)
    //     cout << E2->getBoundaryDofsonGrid()[i] << endl;
    cout << "-------------------------" << endl;
    // 4阶测试
    vector<int> seg2 = {2, 2};
    Mesh<2> *M4 = new Q4Mesh(D, seg2);
    Grid<2> g4 = M4->getGrid(1);

    TemplateElement<2> *E4 = new Quadrilateral_4_Element();
    E4->reinit(g4, *M4);
    for (int i = 0; i < 25; i++)
        cout << E4->getGlobalIndex(i) << endl;
    for (int i = 0; i < 25; i++)
        cout << "phi_xi" << i << ":" << E4->phi_xi(-1 / 4.0, 1 / 4.0, i) << endl;
    for (int i = 0; i < 25; i++)
        cout << "phi_eta" << i << ":" << E4->phi_eta(-1 / 4.0, 1 / 4.0, i) << endl;
    // cout << E4->det_Jacobi(-1, -1);
    return 0;
}